
clear
use "perssonSundellBjps2022_wordings.dta.dta" , replace
 
********************************************************************************
* Table 1. Congruence
********************************************************************************

mean inc1
estimates store a
mean inc2
estimates store b
mean inc3
estimates store c

mean bInc1
estimates store j
mean bInc2
estimates store k
mean bInc3
estimates store l

estimates table a b c ,  se(%9.2f) b(%9.2f)    style(noline)   varlabel
estimates table j k l ,  se(%9.2f) b(%9.2f)    style(noline)   varlabel


********************************************************************************
* Fig 1 
********************************************************************************

* By observations

gen dom31 = bInc3 - bInc1


twoway  ///
(scatter bInc3  bInc1 if dom31 >0 , mcolor(red%30) msymbol(o) msize(medsmall)mlabsize(medsmall)) ///
(scatter bInc3  bInc1 if dom31 <0 , mcolor(blue%30) msymbol(o) msize(medsmall)mlabsize(medsmall)) /// 
(function y=x, range(0 100) lcolor(black) lstyle(dash)) ///
, ///
legend(off) ///
graphregion(color(white) margin(vsmall) )  ///
fysize(100) ///
fxsize(100) ///
ylabel(0(25)100) ///
xlabel(0(25)100) ///
name(Observations, replace) ///
title("Observations") ///
ytitle("High-Income Congruence")

* By countries

sort country 
by country: egen CMbInc1=mean(bInc1)
by country: egen CMbInc3=mean(bInc3)	

gen Mdom31 = CMbInc3 - CMbInc1

replace country = "Czech Republic" if country == "CzechR"
replace country = "New Zealand" if country == "NZealand"

sort country 
by country:  gen one = _n

gen pos =.
replace pos=  12
replace pos=  12 if country ==  "Sweden" 
replace pos=  3 if country ==  "Czech Republic" 
replace pos=  0 if country ==  "Norway" 
replace pos=  6 if country ==  "Portugal" 
replace pos=  6 if country ==  "Poland" 
replace pos=  4 if country ==  "US" 
replace pos=  6 if country ==  "Belgium" 
replace pos=  1 if country ==  "Slovenia" 
	
twoway ///
  (scatter CMbInc3  CMbInc1  if CountIssuesInCountries > 50 & one==1 & Mdom31 >0, mcolor(red) msymbol(o) msize(medsmall) mlabel(country) mlabsize(medsmall) mlabvpos(pos)) ///
  (scatter CMbInc3  CMbInc1  if CountIssuesInCountries > 50 & one==1 & Mdom31 <0, mcolor(blue) msymbol(o) msize(medsmall) mlabel(country) mlabsize(medsmall) mlabvpos(pos)) ///
(function y=x, range(49 62) lcolor(black) lstyle(dash)) ///
, ///
legend(off) ///
graphregion(color(white) margin(tiny) )  ///
fysize(100) ///
fxsize(100) ///
ylabel(50(5)60) ///
xlabel(50(5)60) ///
name(Countries, replace) ///
title("Countries") 

* By issues

sort q_id 
by q_id: egen QInc1=mean(bInc1)
by q_id: egen QInc3=mean(bInc3)	

gen Qdom31 = QInc3 - QInc1

tab Qdom31
twoway ///
  (scatter QInc3  QInc1  if Qdom31 >0,  mcolor(red%30) msymbol(o) msize(medsmall)) ///	
  (scatter QInc3  QInc1  if Qdom31 <0, mcolor(blue%30) msymbol(o) msize(medsmall)) ///
(function y=x, range(20 90) lcolor(black) lstyle(dash)) ///
, ///
legend(off) ///
graphregion(color(white) margin(vsmall) )  ///
fysize(100) ///
fxsize(100) ///
name(Issues, replace) ///
title("Issues") ///
ytitle("High-Income Congruence") ///
xtitle("Low-Income Congruence") 

* By years

sort y3_year 
by y3_year: egen YInc1=mean(bInc1)
by y3_year: egen YInc3=mean(bInc3)	

gen Ydom31 = YInc3 - YInc1

twoway ///
  (scatter YInc3  YInc1  if Ydom31 >0,  mcolor(red%30) msymbol(o) msize(medsmall)) ///
  (scatter YInc3  YInc1  if Ydom31 <0,  mcolor(blue%30) msymbol(o) msize(medsmall)) ///
(function y=x, range(30 80) lcolor(black) lstyle(dash)) ///
, ///
legend(off) ///
graphregion(color(white) margin(tiny) )  ///
fysize(100) ///
fxsize(100) ///
name(Years, replace) ///
title("Years ") ///
xtitle("Low-Income Congruence") ///
ylabel(30(10)80) ///
xlabel(30(10)80) 


graph combine Observations Countries Issues Years,  ///
graphregion(color(gs16)) ///
iscale(1) ///
altshrink ///
l1title("") ///
b1title("") ///
name(tmp, replace) 

graph display tmp, xsize(3.5) ysize(3)

graph export "4scatters.pdf" , fontface(Times) replace as(pdf)
*/

********************************************************************************
* Table 2 
********************************************************************************

quietly eststo: mi estimate, post : reg dom31 gini_disp   i.y0_year i.countryNum i.q_switcher , robust
estimates store a

quietly eststo: reg dom31 donate  i.countryNum i.q_switcher i.y0_year , vce(robust)
estimates store b

replace vturn = vturn / 100

quietly eststo: reg dom31 vturn  i.countryNum i.q_switcher i.y0_year  , vce(robust)
estimates store c

replace ud = ud / 100

quietly eststo: reg dom31 ud  i.countryNum i.q_switcher i.y0_year  , vce(robust)
estimates store d

estout a b c d , cells(b(star fmt(3)) se(par fmt(3))) keep(gini_disp donate vturn ud)	stats( N) style(tex) 
estimates clear


********************************************************************************
* Appendix material
********************************************************************************

********************************************************************************
* Table 2 
********************************************************************************

 egen uniq = nvals(q_id), by(policyarea)
 tab uniq policyarea
 
 
********************************************************************************
* Fig 1 in Appendix
********************************************************************************

gen direction = 1 if bInc1 > bInc3
replace direction = 0  if bInc1 < bInc3

replace country = "CzechR" if country == "Czech Republic" 
replace country = "NZealand" if country == "New Zealand"
replace country = "UK" if country == "United Kingdom"
replace country = "US" if country == "United States"



levelsof country, local(levels) 
foreach l of local levels {
twoway   (scatter   bInc3 bInc1 if country == "`l'" & direction == 1, mcolor(red) msymbol(O) msize(medsmall)) ///
   (scatter   bInc3 bInc1 if country == "`l'" & direction == 0, mcolor(blue) msymbol(O) msize(medsmall)) ///
, ///
legend(off) ///
graphregion(color(white) margin(vsmall))  ///
fysize(90) ///
fxsize(90) ///
ylabel(0(25)100) ///
xlabel( 0(25)100) ///
name(`l', replace) ///
title("`l'") ///
xtitle("") ///
ytitle("") 

}


graph combine  Austria Belgium   CzechR Denmark Finland France Germany Greece Hungary Ireland Italy    Luxembourg  Netherlands Norway Poland Portugal   Slovenia Spain Sweden Switzerland UK ,  ///
altshrink ///
graphregion(color(gs16)) ///
iscale(2) ///
l1title("High-income congruence",size(vsmall)) ///
b1title("Low-income congruence",size(vsmall)) ///
name(tmp, replace) ///
ycommon

graph export "combined1.eps" , fontface(Times) replace as(eps)



 
********************************************************************************
* Fig 2 in Appendix
********************************************************************************

sort bInc1
gen n1 = _n

sort bInc2
gen n2 = _n

sort bInc3
gen n3 = _n


sort dom31
gen n31 = _n

sort countryNum dom31

bysort countryNum: gen cn31 = _n 

egen ccn  =  count(issue_id), by(countryNum) 
replace ccn = ccn / 2


set scheme s2color
 
gen a = 4

gen domNeg = dom31 if dom31 < 0
replace domNeg = abs(domNeg)

levelsof country, local(levels) 
foreach l of local levels {
twoway   (bar dom31  cn31 if country == "`l'" & dom31 > 0, mcolor(white)) ///
 (bar domNeg  cn31  if country == "`l'", mcolor(blue)) ///
(spike a ccn  if country == "`l'", lpattern(dotted) lcolor(black)) , ///
legend(off) ///
graphregion(color(white) margin(vsmall))  ///
fysize(90) ///
fxsize(90) ///
name(`l', replace) ///
title("`l'") ///
xlabel("") ///
xtitle("") ///
ytitle("") 
}


graph combine  Austria Belgium   CzechR Denmark Finland France Germany Greece Hungary Ireland Italy    Luxembourg  Netherlands Norway Poland Portugal   Slovenia Spain Sweden Switzerland UK ,  ///
altshrink ///
graphregion(color(gs16)) ///
iscale(2) ///
l1title("") ///
b1title("") ///
name(tmp, replace) ///
ycommon

graph export "combined2.eps" , fontface(Times) replace as(eps)


recode dom31 (-100/0=-1) (0/100=1) , gen(dprocent)

tab dprocent
sort country

by country: egen cdprocent=mean(dprocent)

********************************************************************************
* Fig 3 in Appendix
********************************************************************************

levelsof country, local(levels) 

foreach l of local levels {
 
twoway (kdensity bInc1 if country == "`l'", lcolor(red) lpattern(dash))   (kdensity bInc3 if country == "`l'", lcolor(blue)) , ///
legend(off) ///
graphregion(color(white) margin(vsmall))  ///
fysize(90) ///
fxsize(90) ///
name(`l', replace) ///
title("`l'") ///
xtitle("") ///
ytitle("") ///
xlabel(0(25)100) ///

}

graph combine  Austria Belgium   CzechR Denmark Finland France Germany Greece Hungary Ireland Italy    Luxembourg  Netherlands Norway Poland Portugal   Slovenia Spain Sweden Switzerland UK ,  ///
altshrink ///
graphregion(color(gs16)) ///
iscale(2) ///
l1title("") ///
b1title("") ///
name(tmp, replace) ///
ycommon

graph export "combined3.eps" , fontface(Times) replace as(eps)

*/

********************************************************************************
* Table 3
********************************************************************************

gen incdiff = inc3 - inc1 
gen incdiffAbs =abs(incdiff)

replace inc1 = inc1 / 10
replace inc2 = inc2 / 10
replace inc3 = inc3 / 10

quietly reg y3_imp inc1     i.y0_year i.countryNum i.q_switcher,  robust
estimates store a
 
quietly reg y3_imp inc2     i.y0_year i.countryNum i.q_switcher ,  robust
estimates store b

quietly reg y3_imp inc3     i.y0_year i.countryNum i.q_switcher   ,  robust 
estimates store c

quietly reg y3_imp inc1 inc2 inc3   i.y0_year i.countryNum i.q_switcher    , robust
estimates store d    


quietly reg y3_imp incdiff inc2      i.y0_year i.countryNum i.q_switcher  ,  robust 
estimates store e
    
estout a b c d e, cells(b(star fmt(3)) se(par fmt(3))) keep(_cons inc1 inc2 inc3 incdiff)	stats(r2  N) style(tex) varlabels(inc1 "Low income" inc2 "Middle income" inc3 "High income" incdiff "High-Low Diff" ) 
estimates clear


********************************************************************************
* Table 4
********************************************************************************

quietly reg y1_imp inc1     i.y0_year i.countryNum i.q_switcher ,  robust
estimates store a
 
quietly reg y1_imp inc2     i.y0_year i.countryNum i.q_switcher ,  robust
estimates store b

quietly reg y1_imp inc3     i.y0_year i.countryNum i.q_switcher ,  robust 
estimates store c

quietly reg y1_imp inc1 inc2 inc3   i.y0_year i.countryNum i.q_switcher   , robust
estimates store d

quietly reg y1_imp incdiff inc2      i.y0_year i.countryNum i.q_switcher ,  robust 
estimates store e
    
estout a b c d e, cells(b(star fmt(3)) se(par fmt(3))) keep(_cons inc1 inc2 inc3 incdiff)	stats(r2  N) style(tex) varlabels(inc1 "Low income" inc2 "Middle income" inc3 "High income" incdiff "High-Low Diff" ) 
estimates clear

********************************************************************************
* Table 5
********************************************************************************


quietly reg y2_imp inc1     i.y0_year i.countryNum i.q_switcher ,  robust
estimates store a
 
quietly reg y2_imp inc2     i.y0_year i.countryNum i.q_switcher ,  robust
estimates store b

quietly reg y2_imp inc3     i.y0_year i.countryNum i.q_switcher ,  robust 
estimates store c

quietly reg y2_imp inc1 inc2 inc3   i.y0_year i.countryNum i.q_switcher   , robust
estimates store d

quietly reg y2_imp incdiff inc2      i.y0_year i.countryNum i.q_switcher ,  robust 
estimates store e
    
estout a b c d e, cells(b(star fmt(3)) se(par fmt(3))) keep(_cons inc1 inc2 inc3 incdiff)	stats(r2  N) style(tex) varlabels(inc1 "Low income" inc2 "Middle income" inc3 "High income" incdiff "High-Low Diff" ) 
estimates clear

********************************************************************************
* Table 6
********************************************************************************

* constructing country weights
gen n = e(N)
gen s = e(sample)

egen countryN =count(issue_id) if s == 1  , by(countryNum) 
gen countryW = (n / 36) / countryN 

quietly reg y3_imp inc1     i.y0_year i.countryNum i.q_switcher [pweight=countryW]  ,  robust
estimates store a
 
quietly reg y3_imp inc2     i.y0_year i.countryNum i.q_switcher [pweight=countryW]  ,  robust
estimates store b

quietly reg y3_imp inc3     i.y0_year i.countryNum i.q_switcher [pweight=countryW]  ,  robust 
estimates store c

quietly reg y3_imp inc1 inc2 inc3   i.y0_year i.countryNum i.q_switcher [pweight=countryW]    , robust
estimates store d    


quietly reg y3_imp incdiff inc2      i.y0_year i.countryNum i.q_switcher [pweight=countryW]  ,  robust 
estimates store e
    
estout a b c d e, cells(b(star fmt(3)) se(par fmt(3))) keep(_cons inc1 inc2 inc3 incdiff)	stats(r2  N) style(tex) varlabels(inc1 "Low income" inc2 "Middle income" inc3 "High income" incdiff "High-Low Diff" ) 
estimates clear

********************************************************************************
* Table 7
********************************************************************************

* constructing question weights
egen questionN =count(issue_id) , by(q_id) 
gen questionW = (n / 145) / questionN 

* effects if income groups with question weights, table 4 in the appendix

quietly reg y3_imp inc1     i.y0_year i.countryNum i.q_switcher [pweight=questionW]  ,  robust
estimates store a
 
quietly reg y3_imp inc2     i.y0_year i.countryNum i.q_switcher [pweight=questionW]  ,  robust
estimates store b

quietly reg y3_imp inc3     i.y0_year i.countryNum i.q_switcher [pweight=questionW]  ,  robust 
estimates store c

quietly reg y3_imp inc1 inc2 inc3   i.y0_year i.countryNum i.q_switcher [pweight=questionW]    , robust
estimates store d    


quietly reg y3_imp incdiff inc2      i.y0_year i.countryNum i.q_switcher [pweight=questionW]  ,  robust 
estimates store e

    
estout a b c d e, cells(b(star fmt(3)) se(par fmt(3))) keep(_cons inc1 inc2 inc3 incdiff)	stats(r2  N) style(tex) varlabels(inc1 "Low income" inc2 "Middle income" inc3 "High income" incdiff "High-Low Diff" ) 
estimates clear

********************************************************************************
* Table 9
********************************************************************************

quietly eststo: mi estimate, post : reg bInc1 gini_disp i.y0_year i.countryNum i.q_switcher , robust
estimates store a

quietly eststo: mi estimate, post : reg bInc3 gini_disp  i.y0_year i.countryNum  i.q_switcher, robust
estimates store b
	
quietly eststo:  reg bInc1 donate  i.countryNum i.q_switcher  i.y0_year , vce(robust)
estimates store c

quietly eststo: reg bInc3 donate  i.countryNum i.q_switcher i.y0_year , vce(robust)
estimates store d

quietly eststo: reg bInc1 vturn  i.countryNum i.q_switcher i.y0_year , vce(robust)
estimates store e

quietly eststo: reg bInc3 vturn  i.countryNum i.q_switcher i.y0_year , vce(robust)
estimates store f

quietly eststo: reg bInc1 ud  i.countryNum i.q_switcher i.y0_year , vce(robust)
estimates store g

quietly eststo: reg bInc3 ud  i.countryNum i.q_switcher i.y0_year , vce(robust)
estimates store h


estout a b c d e f g h , cells(b(star fmt(3)) se(par fmt(3))) keep(gini_disp donate vturn ud)	stats( N) style(tex) 
estimates clear


********************************************************************************
* Figure 4
********************************************************************************

graph twoway ///
(scatter dom31 vturn, mcolor(red%20) msymbol(o) msize(vmed)) ///
(qfitci dom31 vturn , level(95)) ///
, /// 
 legend(off) ///
graphregion(color(white) margin(vsmall) )  ///
fysize(100) ///
fxsize(100) ///
name(Turnout, replace) ///
title("Turnout") ///
ytitle("Inequality in Congruence ") ///
title("Voter Turnout")  ///
xtitle("")


graph twoway ///
(scatter dom31 donate, mcolor(gray%20) msymbol(o) msize(///)) ///
(qfitci dom31 donate) , /// 
 legend(off) ///
graphregion(color(white) margin(vsmall) )  ///
fysize(100) ///
fxsize(100) ///
name(Campaign, replace) ///
title("Campaign") ///
ytitle("Inequality in Congruence ") ///
title("Campaign Regulations") ///
xtitle("")
  

egen gini_dispM = rowmedian(_1_gini_disp _2_gini_disp _3_gini_disp _4_gini_disp _5_gini_disp _6_gini_disp _7_gini_disp _8_gini_disp _9_gini_disp _10_gini_disp _11_gini_disp _12_gini_disp _13_gini_disp _14_gini_disp _15_gini_disp _16_gini_disp _17_gini_disp _18_gini_disp _19_gini_disp _20_gini_disp _21_gini_disp _22_gini_disp _23_gini_disp _24_gini_disp _25_gini_disp _26_gini_disp _27_gini_disp _28_gini_disp _29_gini_disp _30_gini_disp _31_gini_disp _32_gini_disp _33_gini_disp _34_gini_disp _35_gini_disp _36_gini_disp _37_gini_disp _38_gini_disp _39_gini_disp _40_gini_disp _41_gini_disp _42_gini_disp _43_gini_disp _44_gini_disp _45_gini_disp _46_gini_disp _47_gini_disp _48_gini_disp _49_gini_disp _50_gini_disp _51_gini_disp _52_gini_disp _53_gini_disp _54_gini_disp _55_gini_disp _56_gini_disp _57_gini_disp _58_gini_disp _59_gini_disp _60_gini_disp _61_gini_disp _62_gini_disp _63_gini_disp _64_gini_disp _65_gini_disp _66_gini_disp _67_gini_disp _68_gini_disp _69_gini_disp _70_gini_disp _71_gini_disp _72_gini_disp _73_gini_disp _74_gini_disp _75_gini_disp _76_gini_disp _77_gini_disp _78_gini_disp _79_gini_disp _80_gini_disp _81_gini_disp _82_gini_disp _83_gini_disp _84_gini_disp _85_gini_disp _86_gini_disp _87_gini_disp _88_gini_disp _89_gini_disp _90_gini_disp _91_gini_disp _92_gini_disp _93_gini_disp _94_gini_disp _95_gini_disp _96_gini_disp _97_gini_disp _98_gini_disp _99_gini_disp _100_gini_disp)

graph twoway ///
(scatter dom31 gini_dispM, mcolor(green%20) msymbol(o) msize(///)) ///
(qfitci dom31 gini_dispM) , /// 
 legend(off) ///
graphregion(color(white) margin(vsmall) )  ///
fysize(100) ///
fxsize(100) ///
name(Income, replace) ///
title("Issues") ///
ytitle("Inequality in Congruence ") ///
title("Income Inequality") ///
xtitle("")

graph twoway ///
(scatter dom31 ud, mcolor(blue%20) msymbol(o) msize(///)) ///
(qfitci dom31 ud) , /// 
 legend(off) ///
graphregion(color(white) margin(vsmall) )  ///
fysize(100) ///
fxsize(100) ///
name(Union, replace) ///
title("Issues") ///
ytitle("Inequality in Congruence ") ///
title("Union Density") ///
xtitle("")

graph combine Turnout Income Union Campaign,  ///
graphregion(color(gs16)) ///
iscale(1) ///
altshrink ///
l1title("") ///
b1title("") ///
name(tmp, replace) 

graph display tmp, xsize(3.5) ysize(3)

graph export "4reg.pdf" , fontface(Times) replace as(pdf)

********************************************************************************
* Table 11
*******************************************************************************

quietly eststo: mi estimate, post : reg dom31 gini_disp   i.y0_year i.countryNum i.q_switcher i.q_id  , robust
estimates store r1
quietly eststo: reg dom31 donate  i.countryNum i.q_switcher i.y0_year i.q_id , vce(robust)
estimates store r2
quietly eststo: reg dom31 vturn  i.countryNum i.q_switcher i.y0_year i.q_id  , vce(robust)
estimates store r3
quietly eststo: reg dom31 ud  i.countryNum i.q_switcher i.y0_year  i.q_id , vce(robust)
estimates store r4

estout r1 r2 r3 r4, cells(b(star fmt(3)) se(par fmt(3))) keep(gini_disp donate vturn ud)	stats( N) style(tex) 
estimates clear


********************************************************************************
* Table 10
*******************************************************************************

replace inc1  =  inc1  * 10
replace inc2  =  inc2  * 10 
replace inc3  =  inc3  * 10 


collapse (mean) inc1 inc2 inc3 bInc1 bInc2 bInc3 , by(q_id countryNum)

mean inc1
estimates store m
mean inc2
estimates store n
mean inc3
estimates store o


mean bInc1
estimates store p
mean bInc2
estimates store q
mean bInc3
estimates store r

estimates table m n o ,  se(%9.2f) b(%9.2f)    style(noline)   varlabel
estimates table p q r  ,  se(%9.2f) b(%9.2f)    style(noline)   varlabel


log close
